<template>
  <div class="login-container">
    <el-form   label-position="left"
             label-width="0px"
             class="card-box login-form" :rules="loginRules">
      <h3 class="title">注册</h3>

      <el-form-item >
        <span class="svg-container svg-container_login">
          <svg-icon icon-class="user"/>
        </span>
        <el-input v-model="loginForm.username" placeholder="用户名" autoComplete="on"/>
      </el-form-item>

      <el-form-item >
        <span class="svg-container">
          <svg-icon icon-class="password" ></svg-icon>
        </span>
        <el-input type="password" placeholder="密码" v-model="loginForm.password"></el-input>
      </el-form-item>

      <el-form-item >
        <span class="svg-container">
          <svg-icon icon-class="password"></svg-icon>
        </span>
        <el-input type="password" placeholder="请确认密码" v-model="loginForm.password2"></el-input>
      </el-form-item>

      <el-form-item >
        <span class="svg-container el-icon-message"></span>
        <el-input placeholder="邮箱"></el-input>
      </el-form-item>


      <el-form-item >
          <span class="svg-container el-icon-phone"></span>
        <el-input placeholder="手机"></el-input>
      </el-form-item>

      <el-form-item >
          <span class="svg-container el-icon-tickets"></span>
        <el-input placeholder="昵称" v-model="loginForm.nickname"></el-input>
      </el-form-item>

      <el-form-item align="center">
          <el-radio v-model="loginForm.sex" label="男">男</el-radio>
          <el-radio v-model="loginForm.sex" label="女">女</el-radio>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" style="width:100%;"  @click.native.prevent="signup()">
          注册
        </el-button>
      </el-form-item>
    </el-form>

  </div>

</template>

<script>
  export default {
    data() {
      return {
        loginForm: {
          username: '',
          password: '',
          password2:'',
          sex:'男',
          nickname:'',
          roleId:'4'
        },
        loginRules: {
          username: [{required: true, trigger: 'blur', message: "请输入用户名"}],
          password: [{required: true, trigger: 'blur', message: "请输入密码"}],
          password2: [{required: true, trigger: 'blur', message: "请再次输入密码"}],
        }
      }

    },
    methods:{
      signup() {
        if(this.loginForm.password==this.loginForm.password2){
          this.api({
            url: "/user/addUser",
            method: "post",
            data:this.loginForm
          }).then(data => {
            this.$message({
              message: '恭喜,注册成功',
              type: 'success'
            });
            this.$router.push({path:'/login'});
          })
        }else{
          this.$message.error(
            '密码不正确，请再尝试'
          );
        }

      } 
    }
    
  }
</script>

<style rel="stylesheet/scss" lang="scss">
  @import "../../styles/mixin.scss";
  $bg: #2d3a4b;//背景颜色
  $dark_gray: #d8d4cd;  //小图标的颜色
  $light_gray: rgb(238, 238, 238);

  .login-container {
    @include relative;
    height: 100vh;
    background-color: $bg;
    input:-webkit-autofill {
      
      -webkit-text-fill-color: #fff !important;
    }
    input {
      background: transparent;
      border: 10px;
      -webkit-appearance: none;
      border-radius: 0px;
      padding: 12px 5px 12px 15px;
      color: $light_gray;
      height: 47px;
    }
    .el-input {
      display: inline-block;
      height: 47px;
      width: 85%;
    }
    .tips {
      font-size: 14px;
      color: #fff;
      margin-bottom: 10px;
    }
    .svg-container {
      padding: 6px 5px 6px 15px;
      color: $dark_gray;
      vertical-align: middle;
      width: 30px;
      display: inline-block;
      &_login {
        font-size: 20px;
      }
    }
    .title {
      font-size: 26px;
      color: $light_gray;
      margin: 0px auto 40px auto;
      text-align: center;
      font-weight: bold;
    }
    .login-form {
      position: absolute;
      left: 0;
      right: 0;
      width: 400px;
      padding: 35px 35px 15px 35px;
      margin: 10px auto;
    }
    .el-form-item {
      border: 1px solid rgba(255, 255, 255, 0.1);
      background: rgba(0, 0, 0, 0.1);
      border-radius: 5px;
      color: #454545;
    }
    .show-pwd {
      position: absolute;
      right: 10px;
      top: 7px;
      font-size: 16px;
      color: $dark_gray;
      cursor: pointer;
    }
    .thirdparty-button {
      position: absolute;
      right: 35px;
      bottom: 28px;
    }
  }
</style>
